package com.yami.shop.platform.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.dto.OrderRefundDto;
import com.yami.shop.bean.model.OrderRefund;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.OrderRefundService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yami
 */
@RestController
@AllArgsConstructor
@RequestMapping("/platform/orderRefund")
@Tag(name = "订单退款")
public class OrderRefundController {

    private final OrderRefundService orderRefundService;

    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('platform:orderRefund:page')")
    @Operation(summary =  "分页查询", description = "分页查询")
    @Parameters(value = {
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    public ServerResponseEntity<IPage<OrderRefundDto>> getOrderRefundPage(PageParam<OrderRefundDto> page,@ParameterObject OrderRefundDto orderRefundDto,
                                                                    @RequestParam(required = false) String startTime,
                                                                    @RequestParam(required = false) String endTime) {
        IPage<OrderRefundDto> resp = orderRefundService.getPage(page, orderRefundDto, startTime, endTime, 1);
        return ServerResponseEntity.success(resp);
    }

    @GetMapping("/info")
    @PreAuthorize("@pms.hasPermission('platform:orderRefund:info')")
    @Operation(summary =  "获取订单退款信息", description = "获取订单退款信息")
    @Parameters(value = {
            @Parameter(name = "refundId", description = "退款id"),
            @Parameter(name = "shopId", description = "店铺id")
    })
    public ServerResponseEntity<OrderRefund> info(@RequestParam("refundId") Long refundId, @RequestParam("shopId") Long shopId) {
        OrderRefund orderRefund = orderRefundService.getOrderRefundById(refundId, shopId);
        return ServerResponseEntity.success(orderRefund);
    }

}
